<!DOCTYPE html>
<html>
<head>
    <title>章节配置测试</title>
</head>
<body>
    <h1>章节配置测试</h1>
    <button onclick="testLogin()">测试登录</button>
    <button onclick="testChapters()">测试章节配置</button>
    <div id="result"></div>

    <script>
        let token = null;
        
        async function testLogin() {
            try {
                const response = await fetch('http://localhost:806/api/auth/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({
                        username: 'admin',
                        password: 'admin123'
                    })
                });
                
                const result = await response.json();
                if (result.success) {
                    token = result.data.tokens.accessToken;
                    document.getElementById('result').innerHTML = '<p>登录成功，token已获取</p>';
                } else {
                    document.getElementById('result').innerHTML = '<p>登录失败: ' + result.message + '</p>';
                }
            } catch (error) {
                document.getElementById('result').innerHTML = '<p>登录错误: ' + error.message + '</p>';
            }
        }
        
        async function testChapters() {
            if (!token) {
                document.getElementById('result').innerHTML = '<p>请先登录</p>';
                return;
            }
            
            try {
                const response = await fetch('http://localhost:806/api/chapter-config', {
                    headers: {
                        'Authorization': 'Bearer ' + token
                    }
                });
                
                const result = await response.json();
                if (result.success) {
                    const activeChapters = result.data.filter(config => config.isActive);
                    document.getElementById('result').innerHTML = 
                        '<h3>章节配置数据:</h3>' +
                        '<pre>' + JSON.stringify(activeChapters, null, 2) + '</pre>' +
                        '<p>启用的章节数量: ' + activeChapters.length + '</p>';
                } else {
                    document.getElementById('result').innerHTML = '<p>获取章节配置失败: ' + result.message + '</p>';
                }
            } catch (error) {
                document.getElementById('result').innerHTML = '<p>章节配置错误: ' + error.message + '</p>';
            }
        }
    </script>
</body>
</html>